package com.bdth.bdthmall.api.epoint.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bdth.bdthmall.api.annotation.AuthToken;
import com.bdth.bdthmall.api.epoint.vo.OrderProductVo;
import com.bdth.bdthmall.api.epoint.vo.OrderRequestVo;
import com.bdth.bdthmall.api.epoint.vo.ResponseOrderVo;
import com.bdth.bdthmall.api.epoint.vo.ResponseProductPoolVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by Administrator on 2020/1/14.
 */
@RestController
@RequestMapping("/ecservice")
public class OrderController {
    @RequestMapping(value = "/createOrder", method = RequestMethod.POST)
    @AuthToken
    public ResponseOrderVo createOrder(@RequestParam String data){
        JSONObject json = JSONObject.parseObject(data);
        OrderRequestVo orderRequestVo = new OrderRequestVo();
        orderRequestVo.setTradeNO(json.getString("tradeNO"));
        JSONArray sku = json.getJSONArray("sku");
        List<OrderProductVo> list = JSONObject.parseArray(sku.toString(),OrderProductVo.class);
        orderRequestVo.setSku(list);
        orderRequestVo.setAmount(json.getBigDecimal("amount"));
        ResponseOrderVo responseOrderVo = new ResponseOrderVo();

        responseOrderVo.setOrderId("20170902341774133");
        responseOrderVo.setArriveData("2017-09-18");
        responseOrderVo.setFreight(0);
        responseOrderVo.setSku(list);
        responseOrderVo.setAmount(orderRequestVo.getAmount());
        responseOrderVo.setIsSuccess(true);
        responseOrderVo.setReturnMsg("创建订单完成");
        return responseOrderVo;
    }
    /**
     * {"accessToken":"ff587d8b-b9fe-4d21-a8d6-8f519d407cab" ,"appKey":"epoint","tradeNO":"11748688","sku":[{"skuId":"120855119","num":1,"price":100.00},{"skuId":"11837193","num":2,"price":200.00}],"name":"收货人李三","provinceId":"110","cityId":"025","countyId":"01","townId":"01","address":"国泰路100号","phone":"025-88888888","mobile":"13838389438","email":"suning@suning.com","invoiceState":1,"invoiceType":2,"companyName":"新点软件有限公司","invoiceContent":1,"amount":500.00,"freight":5,"payment":1,"remark":"备注信息" }
     */
}
